package com.cndw.kongfu.messagepush;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;

import com.cndw.rpg.framework.codec.BaseFrameDecode;
import com.cndw.rpg.framework.execution.SimpleThreadFactory;
import com.cndw.rpg.framework.socket.GameServerIdleStateHandler;

public class MyChannelPipelineFactory implements ChannelPipelineFactory {
	private static final ExecutionHandler executionHandler;
	private static final Timer timer;

	static {
		java.util.concurrent.ThreadFactory threadFactory = new SimpleThreadFactory("FarmeWorker");
		ThreadPoolExecutor executor = new OrderedMemoryAwareThreadPoolExecutor(500, 0L, 0L, 60L, TimeUnit.SECONDS, threadFactory);
		executor.allowCoreThreadTimeOut(false);
		executionHandler = new ExecutionHandler(executor);
		timer = new HashedWheelTimer(new SimpleThreadFactory("hearbeat"), 1300L, TimeUnit.MILLISECONDS, 512);
	}
	@Override
	public ChannelPipeline getPipeline() throws Exception {
		ChannelPipeline pipeline =  Channels.pipeline();
//		pipeline.addLast("framer", new BaseFrameDecode());
//		pipeline.addLast("hearbeat", new GameServerIdleStateHandler(timer, 600, 0, 0));
		pipeline.addLast("handler", new MyClientHandler());
		return pipeline;
	}
}